/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#pragma once
#include <logbase.h>
// hc circular queue struct
struct cCirQueRoot
{
    void **ptr;          // queue ptr
    long total;          // queue malloc element size.
    long len;            // queue used element len.
    long rid;            // queue read id.
    long wid;            // queue write id.
    __compar_fn_t cmpfn; // queue cmp fn, for qsort and bsearch
    int withmt;          // queue option with mutex flag.0:not, 1:use
    pthread_mutex_t mut; // queue mutex
};
typedef struct cCirQueRoot cCirQueRoot;
#define CDEQUE_INIT_SIZE (8)
#define CDEQUE_WARN_SIZE (1L * 1024 * 1024)
int cCirQueInit(cCirQueRoot *cqptr, __compar_fn_t cfgcmp, int cfgWl);
int cCirQueFree(cCirQueRoot *cqptr);
long cCirQueSize(cCirQueRoot *cqptr);
int cCirQuePushBack(cCirQueRoot *cqptr, void *ptr);
int cCirQuePushFront(cCirQueRoot *cqptr, void *ptr);
int cCirQuePullFront(cCirQueRoot *cqptr, void **optr);
int cCirQuePullBack(cCirQueRoot *cqptr, void **optr);
int cCirQueSort(cCirQueRoot *cqptr);
long cCirQueSearch(cCirQueRoot *cqptr, void *findKey);
